package com.youease.chris.model.proxy
{
	import com.youease.chris.model.vo.LayerData;
	import com.youease.chris.model.vo.MapData;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	public class MapDataProxy extends Proxy implements IProxy
	{
		public function MapDataProxy(data:MapData)
		{
			super(data.name, data);
		}
		
		/**
		 * 添加层信息到地图
		 * @param layerData:层信息
		 */
		public function addLayer(layerData:LayerData):void {
			for each(var layer:LayerData in mapData.layers) {
				if(layer.name == layerData.name) {
					trace("层已经存在");
					return;
				}
			}
			mapData.layers.push(layerData);
		}
		
		/**
		 * 删除层
		 * @param layerData:层信息
		 */
		public function deleteLayer(layerData:LayerData):void {
			var deleteIndex:int = -1;
			for each(var layer:LayerData in mapData.layers) {
				if(layer.name == layerData.name) {
					deleteIndex = mapData.layers.indexOf(layer);
					break;
				}
			}
			if(deleteIndex != -1) {
				mapData.layers.splice(deleteIndex,1);
			}
		}
		
		public function get mapData():MapData {
			return this.data as MapData;
		}
	}
}